package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;

/************************************************************************************
 * @File name :ProductBrandInfoWapper.java
 * @Author :ligaoge
 * @Date : 2016年8月23日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class ProductBrandInfoWapper {
	MongoDBDriver mdd  = YmtMongoDriverFactroy.getInstance_YmtProductDBdriver("ProductBrandInfo");

	    public ProductBrandInfoWapper() {
	    }
		
	    public ArrayList <Map> getProductBrandInfoByBrandId(Integer BrandId) throws Exception {
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"BrandId\":"+BrandId+ "}",
	                "{'_id':1,'BrandId':1, 'BrandName':1, 'BrandEnName':1, 'KeyWord':1, 'ProductCount':1, 'BrandLogoUrl':1, 'BrandBannerUrl':1,"
	                +"'BrandDescription':1,'AddTime':1,'AddUser':1,'UpdateTime':1,'UpdateUser':1,'Action':1,'TagList':1}" , 1,"");
	        try {
	            if (list.size() > 0) {
	                return  list;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data BrandId:" + BrandId);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    /**
	     * 按BrandId查询出一条记录
	     * @param BrandId
	     * @return
	     * @throws Exception
	     */
	    public ArrayList <Map> getProductBrandInfoById(Integer BrandId) throws Exception {
	    	mdd  = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("ProductBrandInfo");
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"BrandId\":"+BrandId+ "}",1);
	        try {
	            if (list.size() > 0) {
	                return  list;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data BrandId:" + BrandId);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    /**
	     * 查询记录
	     * @param limit
	     * @return
	     * @throws Exception
	     */
	    public ArrayList <Map> getProductBrandInfos(Integer limit) throws Exception {
	    	mdd  = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("ProductBrandInfo");
	    	if(limit<1){
	    		limit=1;
	    	}
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{}",limit);
	        try {
	            if (list.size() > 0) {
	                return  list;
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return null;
	    }
	    public ArrayList <Map> getProductBrandInfoByBrandEnName(String BrandEnName) throws Exception {
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"BrandEnName\":'"+BrandEnName+ "'}",
	                "{'_id':1,'BrandId':1, 'BrandName':1, 'BrandEnName':1, 'KeyWord':1, 'ProductCount':1, 'BrandLogoUrl':1, 'BrandBannerUrl':1,"
	                +"'BrandDescription':1,'AddTime':1,'AddUser':1,'UpdateTime':1,'UpdateUser':1,'Action':1,'TagList':1}" , 1,"");
	        try {
	            if (list.size() > 0) {
	                return  list;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data BrandEnName:" + BrandEnName);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    
	    public static void main(String args[]) throws Exception{
	    	ProductBrandInfoWapper productBrandInfoWapper=new ProductBrandInfoWapper();
	    	/*ArrayList<Map>mm = productBrandInfoWapper.getProductBrandInfoByBrandId(21215);
	    	mm.get(0).get("BrandName");
	    	System.out.println(mm.get(0).get("BrandName"));*/
	    	ArrayList<Map>mm = productBrandInfoWapper.getProductBrandInfoByBrandEnName("IBM");
	    	System.out.println(mm.get(0).get("BrandId"));
	    }
}
